//package com.ionehe.group.common.uaa.ex.ano;
//
//import com.ionehe.group.common.io.Response;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.AfterReturning;
//import org.aspectj.lang.annotation.AfterThrowing;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.aop.support.AopUtils;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestAttributes;
//import org.springframework.web.context.request.RequestContextHolder;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Map;
//
//@Aspect
//@Component
//@Slf4j
//public class UaaLoginLogAspect {
//    @Pointcut("@annotation(com.ionehe.group.common.uaa.ex.ano.UaaLoginLog)")
//    public void pointCut() {
//    }
//
//    /**
//     * 后置通知，保存登录成功 日志
//     */
//    @AfterReturning(pointcut = "pointCut()", returning = "result")
//    public void saveSysLog(JoinPoint joinPoint, Response<Map<String, String>> result) {
//        // 登录日志实体类
//        LogLogin logLogin = new LogLogin();
//
//        // 保存登录成功日志
//        logLogin.setUsername(result.getData().getUsername());
//        logLogin.setIp(getRequestIp());
//        logLogin.setType(HttpContextUtils.getRequestFrom());
//        logLogin.setStatus(0);
//        iLogLoginService.save(logLogin);
//    }
//
//    private String getRequestIp() {
//        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
//        if (request.getHeader("x-forwarded-for") == null) {
//            return request.getRemoteAddr();
//        }
//        return request.getHeader("x-forwarded-for");
//    }
//
//}
//
